<?php
function webform_submission_update_DE($node, $submission) {
  //-----------------------Special 'split_family' add by Tanky-------------------------------------------------------
  /*if (isset($_POST['submitted']['for_allowances_calculation']) && !isset($_POST['submitted']['for_allowances_calculation']['split_family'])) {
     $split_family_cid = 52;
     if (isset($submission->data[$split_family_cid]['value'][0])) {
       $submission->data[$split_family_cid]['value'][0] = '';
     }
  }*/
  //-----------------------------End---------------------------------------------------------------------------------
  
  //-----------------------Special 'upload file' add by Tanky-------------------------------------------------------
  // Delete the upload file data if 'is_approver' change from 'no' to 'yes'
  $is_approver_cid     = 40;
  $attach_approval_cid = 43;
  if (isset($submission->data[$is_approver_cid]['value'][0]) && $submission->data[$is_approver_cid]['value'][0]==1) {
    if (isset($submission->data[$attach_approval_cid]['value'][0])) {
      $fid = $submission->data[$attach_approval_cid]['value'][0]; //echo $fid;exit;
      if ($fid>0) {
        unset($submission->data[$attach_approval_cid]);
        
        $sql = "update {file_managed} set status=0 where fid=".$fid;
        db_query($sql);
      }
    }
  }
  //-----------------------------End---------------------------------------------------------------------------------
}

function webform_submission_update_JAP($node, $submission) {
  //-----------------------Special 'split_family' add by Tanky-------------------------------------------------------
  /*if (isset($_POST['submitted']['for_allowances_calculation']) && !isset($_POST['submitted']['for_allowances_calculation']['split_family'])) {
     $split_family_cid = 52;
     if (isset($submission->data[$split_family_cid]['value'][0])) {
       $submission->data[$split_family_cid]['value'][0] = '';
     }
  }*/
  //-----------------------------End---------------------------------------------------------------------------------
  
  //-----------------------Special 'upload file' add by Tanky-------------------------------------------------------
  // Delete the upload file data if 'is_approver' change from 'no' to 'yes'
  $is_approver_cid     = 40;
  $attach_approval_cid = 43;
  if (isset($submission->data[$is_approver_cid]['value'][0]) && $submission->data[$is_approver_cid]['value'][0]==1) {
    if (isset($submission->data[$attach_approval_cid]['value'][0])) {
      $fid = $submission->data[$attach_approval_cid]['value'][0]; //echo $fid;exit;
      if ($fid>0) {
        unset($submission->data[$attach_approval_cid]);
        
        $sql = "update {file_managed} set status=0 where fid=".$fid;
        db_query($sql);
      }
    }
  }
  //-----------------------------End---------------------------------------------------------------------------------
}

function webform_submission_update_MEX($node, $submission) {
   //-----------------------Special 'upload file' add by Tanky-------------------------------------------------------
  // Delete the upload file data if 'is_approver' change from 'no' to 'yes'
  $is_approver_cid     = 40;
  $attach_approval_cid = 43;
  if (isset($submission->data[$is_approver_cid]['value'][0]) && $submission->data[$is_approver_cid]['value'][0]==1) {
    if (isset($submission->data[$attach_approval_cid]['value'][0])) {
      $fid = $submission->data[$attach_approval_cid]['value'][0]; //echo $fid;exit;
      if ($fid>0) {
        unset($submission->data[$attach_approval_cid]);
        
        $sql = "update {file_managed} set status=0 where fid=".$fid;
        db_query($sql);
      }
    }
  }    
}

function webform_submission_update_TUR($node, $submission) {
  //-----------------------Special 'upload file' add by Tanky-------------------------------------------------------
  // Delete the upload file data if 'is_approver' change from 'no' to 'yes'
  $is_approver_cid     = 40;
  $attach_approval_cid = 43;
  if (isset($submission->data[$is_approver_cid]['value'][0]) && $submission->data[$is_approver_cid]['value'][0]==1) {
    if (isset($submission->data[$attach_approval_cid]['value'][0])) {
      $fid = $submission->data[$attach_approval_cid]['value'][0]; //echo $fid;exit;
      if ($fid>0) {
        unset($submission->data[$attach_approval_cid]);
        
        $sql = "update {file_managed} set status=0 where fid=".$fid;
        db_query($sql);
      }
    }
  }
}




function webform_submission_update_AU($node, $submission) {
   //-----------------------Special 'upload file' add by Tanky-------------------------------------------------------
  // Delete the upload file data if 'is_approver' change from 'no' to 'yes'
  $is_approver_cid     = 40;
  $attach_approval_cid = 43;
  if (isset($submission->data[$is_approver_cid]['value'][0]) && $submission->data[$is_approver_cid]['value'][0]==1) {
    if (isset($submission->data[$attach_approval_cid]['value'][0])) {
      $fid = $submission->data[$attach_approval_cid]['value'][0]; //echo $fid;exit;
      if ($fid>0) {
        unset($submission->data[$attach_approval_cid]);
        
        $sql = "update {file_managed} set status=0 where fid=".$fid;
        db_query($sql);
      }
    }
  }    
}
